﻿using System.ComponentModel.Composition;
using System.Waf.Applications;
using HighLandirect.Applications.Views;
using HighLandirect.Domain;

namespace HighLandirect.Applications.ViewModels
{
    [Export]
    public class CustomerViewModel : ViewModel<ICustomerView>
    {
        private bool isValid = true;
        private Customer customer;

        
        [ImportingConstructor]
        public CustomerViewModel(ICustomerView view)
            : base(view)
        {
        }


        public bool IsEnabled { get { return Customer != null; } }

        public bool IsValid
        {
            get { return isValid; }
            set
            {
                if (isValid != value)
                {
                    isValid = value;
                    RaisePropertyChanged("IsValid");
                }
            }
        }

        public Customer Customer
        {
            get { return customer; }
            set
            {
                if (customer != value)
                {
                    customer = value;
                    RaisePropertyChanged("Customer");
                    RaisePropertyChanged("IsEnabled");
                }
            }
        }


        public void Focus()
        {
            ViewCore.FocusFirstControl();
        }

        public void SetJusho(string PostalCD)
        {
            var postalConverter = new PostalCDConverter();
            postalConverter.GetAddress(PostalCD);
            customer.SetAddress(postalConverter);
        }
    }
}
